package com.yusysqdy.gulimail.order.config;

import com.zaxxer.hikari.HikariDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import javax.sql.DataSource;

/**
 * @program: gulimail
 * @contact: qindy0116@126.com
 * @author: Mr.DYQin
 * @create: 2021-02-20 18:02
 * @Description:
 **/

@Configuration
public class MySeataConfig {
	@Bean
	public DataSource dataSource(DataSourceProperties dataSourceProperties) {
		HikariDataSource dataSource =
				dataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
		if (StringUtils.hasText(dataSourceProperties.getName())) {
			dataSource.setPoolName(dataSourceProperties.getName());
		}
		return new DataSourceProxy(dataSource);
	}
}
